<template>
  <div class="app-container">
    <!--顶部搜索条件-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="检测商品" prop="goodsName">
        <el-input
          v-model="queryParams.goodsName"
          placeholder="请输入检测商品"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上报状态" prop="reportStatus">
        <el-select
          v-model="queryParams.reportStatus"
          placeholder="请选择上报状态"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.dispose_report_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="处置时间">
        <el-date-picker
          v-model="disposeTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!--表格-->
    <el-table v-loading="loading" :data="disposedList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商品名称" prop="goodsName" align="center" width="120" />
      <el-table-column label="检测项目" prop="itemName" align="center" width="200" />
      <el-table-column label="检测时间" prop="checkTime" align="center" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="上报状态" prop="reportStatus" align="center" width="120">
        <template slot-scope="scope">
          <span>
            {{ selectDictLabels(dict.type.dispose_report_status,scope.row.reportStatus) }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="处置时间" prop="disposeTime" align="center" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.disposeTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处置数量" prop="disposeNum" align="center" width="80" />
      <el-table-column label="处置人" prop="disposePeople" align="center" width="120" />
      <el-table-column label="处置结果" prop="disposeResult" align="center" width="120" />
      <el-table-column label="处置方式" prop="disposeType" align="center" width="120" />

      <el-table-column label="操作" align="center" class-name="small-padding" fixed="right" min-width="250">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleDetail(scope.row)"
            v-hasPermi="['check:dispose:query']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-upload2"
            @click="handleReport(scope.row)"
            v-hasPermi="['check:dispose:report']"
          >上报快件一件事</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 详情弹窗 -->
    <el-dialog title="" :visible.sync="disposeOpen" width="600px" :close-on-click-modal="false">
      <el-descriptions class="margin-top" title="检测详情" :column="2" border>
        <el-descriptions-item label="检测商品">{{disposeData.goodsName}}</el-descriptions-item>
        <el-descriptions-item label="检测项目">{{disposeData.itemName}}</el-descriptions-item>
        <el-descriptions-item label="检测时间">{{parseTime(disposeData.checkTime)}}</el-descriptions-item>
        <el-descriptions-item label="检测值">{{disposeData.checkValue}}</el-descriptions-item>
        <el-descriptions-item label="备注" :span="2">{{disposeData.remark}}</el-descriptions-item>
      </el-descriptions>



      <el-descriptions title="处置详情" :column="2" border class="margin-top" style="margin-top: 20px">
        <el-descriptions-item label="处置时间">{{parseTime(disposeData.disposeTime)}}</el-descriptions-item>
        <el-descriptions-item label="处置数量">{{disposeData.disposeNum}}</el-descriptions-item>
        <el-descriptions-item label="处置人">{{disposeData.disposePeople}}</el-descriptions-item>
        <el-descriptions-item label="处置结果">{{disposeData.disposeResult}}</el-descriptions-item>
        <el-descriptions-item label="处置方式" :span="2">{{disposeData.disposeType}}</el-descriptions-item>
        <el-descriptions-item label="处置人签名" :span="2">
          <template slot="label">
            处置人签名
          </template>
          <img style="width: 120px;height: 120px;margin-left: 10px" :src="disposeData.signUrl"/>
        </el-descriptions-item>
        <el-descriptions-item label="附件(图片)" :span="2">
          <template slot="label">
            附件(图片)
          </template>
          <img v-for="(item, index) in disposeData.imageAttachList" style="width: 120px;height: 120px;margin-left: 10px" :src="item" />
        </el-descriptions-item>

        <el-descriptions-item label="附件(视频)" :span="2">
          <template slot="label">
            附件(视频)
          </template>
          <video v-for="(item, index) in disposeData.videoAttachList" style="width: 120px;height: 120px;margin-left: 10px" :src="item" />
        </el-descriptions-item>
      </el-descriptions>
    </el-dialog>
  </div>
</template>

<script>
//已处置组件
import {getDispose, listDisposed} from "@/api/check/dispose";

export default {
  name: "processed",
  dicts: ['dispose_report_status'],
  data(){
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        goodsName: undefined
      },
      showSearch: true,
      disposeTime: [],
      checkTime: [],
      loading: false,
      disposedList: [],
      total: 0,
      disposeData: {},
      disposeOpen: false
    }
  },
  created() {
    this.initDisposeTime()
  },
  methods: {
    initDisposeTime(){
      // 使用
      const today = new Date();
      const endTime = this.formatDate(today);

      const start = new Date();
      start.setDate(today.getDate() - 6);
      const startTime = this.formatDate(start);
      this.disposeTime = [startTime,endTime]
    },
    formatDate(date) {
      const y = date.getFullYear();
      const m = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始
      const d = String(date.getDate()).padStart(2, '0');
      return `${y}-${m}-${d}`;
    },
    getList(){
      this.loading = true
      listDisposed(this.addDateTimeRange(this.queryParams,this.disposeTime)).then(response => {
        this.disposedList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    handleQuery(){

    },
    resetQuery(){

    },
    handleDetail(row){
      this.disposeData = {}
      getDispose(row.id).then(response => {
        this.disposeData = response.data
        this.disposeOpen = true
      })
    },
    handleDelete(){

    },
    handleReport(){

    }
  }
}
</script>

<style scoped>

</style>
